{{$v := Stored.values}}
{{$v.Get "domain"}} {
    root {{$v.Get "root"}}

    {{AddonAttr "" "log"}}

    {{if $v.Get "header_path"}}
    header {{$v.Get "header_path"}} {
        {{IteratorKV "header" "" "        "}}
    }
    {{end}}

    {{if eq ($v.Get "tls") "1"}}
        {{if and ($v.Get "tls_cert") ($v.Get "tls_key")}}
    tls {{$v.Get "tls_cert"}} {{$v.Get "tls_key"}}
        {{else if $v.Get "tls_email"}}
    tls {{$v.Get "tls_email"}}
        {{end}}
    {{else}}
    tls off
    {{end}}

    {{if eq ($v.Get "gzip") "1"}}
    gzip {
        {{AddonAttr "gzip" "ext"}}
        {{AddonAttr "gzip" "not"}}
        {{AddonAttr "gzip" "level"}}
        {{AddonAttr "gzip" "min_length"}}
    }
    {{end}}

    {{if eq ($v.Get "fastcgi") "1"}}
    fastcgi {{$v.Get "fastcgi_path"}} {{$v.Get "fastcgi_endpoint"}} {{$v.Get "fastcgi_preset"}} {
        {{AddonAttr "fastcgi" "ext"}}
        {{AddonAttr "fastcgi" "split"}}
        {{AddonAttr "fastcgi" "index"}}
        {{IteratorKV "fastcgi" "env" "        env    "}}
        {{AddonAttr "fastcgi" "except"}}
        {{AddonAttr "fastcgi" "pool"}}
    }
    {{end}}
    
    {{if eq ($v.Get "proxy") "1"}}
    proxy {{$v.Get "proxy_from"}} {{$v.Get "proxy_to"}} {
        {{AddonAttr "proxy" "policy"}}
        {{AddonAttr "proxy" "fail_timeout"}}
        {{AddonAttr "proxy" "max_fails"}}
        {{AddonAttr "proxy" "try_duration"}}
        {{AddonAttr "proxy" "try_interval"}}
        {{AddonAttr "proxy" "health_check"}}
        {{AddonAttr "proxy" "health_check_interval"}}
        {{AddonAttr "proxy" "health_check_timeout"}}
        {{IteratorKV "proxy" "header_upstream" "        header_upstream    "}}
        {{IteratorKV "proxy" "header_downstream" "        header_downstream    "}}
        {{AddonAttr "proxy" "keepalive"}}
        {{AddonAttr "proxy" "without"}}
        {{AddonAttr "proxy" "except"}}
        {{AddonAttr "proxy" "upstream"}}
        {{AddonAttr "proxy" "insecure_skip_verify"}}
        {{AddonAttr "proxy" "preset"}}
    }
    {{end}}

    {{if eq ($v.Get "browse") "1"}}
    browse {{$v.Get "browse_path"}} {{$v.Get "browse_tmpl"}}
    {{end}}

    {{if eq ($v.Get "expires") "1"}}
    expires {
    {{IteratorKV "expires" "match" "        match    "}}
    }
    {{end}}

    {{if eq ($v.Get "ipfilter") "1"}}
    ipfilter {{$v.Get "ipfilter_paths"}} {
        rule block
        {{AddonAttr "ipfilter" "ip"}}
        {{AddonAttr "ipfilter" "country"}}
        {{AddonAttr "ipfilter" "database"}}
        {{AddonAttr "ipfilter" "blockpage"}}
        {{AddonAttr "ipfilter" "strict"}}
    }
    {{end}}

    {{$v.Get "rewrite_rule"}}
}
